from django.shortcuts import render,HttpResponse
from django.shortcuts import render, HttpResponse
from .myforms import StudentForm
from .models import Student
from django.db.models import Q,F
# Create your views here.
def addstudent(request):
    a=Student.objects.filter(Q(name='tyy')).update(age=F('age')+10)
    print(a)
    if request.method == 'GET':
        form = StudentForm()  # 创建form组件  modelform
        return render(request, 'student2.html', {'form': form})

    if request.method == 'POST':
        form = StudentForm(request.POST)
        if form.is_valid():
            student = Student(**form.cleaned_data)
            student.save()

        else:
            return render(request, 'student2.html', {'form': form})
        return HttpResponse('ok')